package me.yushuai.wukong.base.controller;

import me.yushuai.wukong.base.annotation.ActionLog;
import me.yushuai.wukong.base.api.CartonApi;
import me.yushuai.wukong.base.api.dto.CartonDTO;
import me.yushuai.wukong.base.api.dto.CreateCartonDTO;
import me.yushuai.wukong.base.api.dto.PagingSearchCarton;
import me.yushuai.wukong.base.api.dto.UpdateCartonDTO;
import me.yushuai.wukong.base.service.CartonService;
import me.yushuai.wukong.common.dto.PageDTO;
import me.yushuai.wukong.common.exceptin.DuplicateBizIdException;
import me.yushuai.wukong.common.exceptin.NotExistException;
import me.yushuai.wukong.common.mvc.BaseController;
import me.yushuai.wukong.common.mvc.RestRequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

/**
 * 装箱Web接口实现类，接口采用RESTFull方式定义
 *
 * @author zhoushuai@189.cn
 * @date 2022-09-09
 */
@RestController
@RestRequestMapping
public class CartonController extends BaseController implements CartonApi {

    private final CartonService cartonService;

    @Autowired
    public CartonController(CartonService cartonService) {
        this.cartonService = cartonService;
    }

    @Override
    @ActionLog("crate a Carton recode.")
    public Long createCarton(CreateCartonDTO dto) throws DuplicateBizIdException {
        return this.cartonService.createCarton(dto);
    }

    @Override
    @ActionLog("change a Carton by id.")
    public Long editCarton(Long cartonId, UpdateCartonDTO dto) throws NotExistException {
        dto.setCartonId(cartonId);
        return this.cartonService.updateCarton(dto);
    }

    @Override
    @ActionLog("delete a Carton recode by id.")
    public Long deleteCarton(Long cartonId) throws NotExistException {
        this.cartonService.deleteCarton(cartonId);
        return cartonId;
    }


    @Override
    @ActionLog("get a Carton by id.")
    public CartonDTO getById(Long cartonId) throws NotExistException {
        return this.cartonService.findById(cartonId);
    }

    @Override
    @ActionLog("search the Cartons.")
    public PageDTO<CartonDTO> pagingSearchCarton(PagingSearchCarton pagingSearch) {
        return this.cartonService.pagingSearchCarton(pagingSearch);
    }

    @Override
    @ActionLog("check the bizId if exists.")
    public boolean existByBizId(String bizId) {
        return this.cartonService.existByBizId(bizId);
    }
}
